import functools
from flask import session, g


# 新闻排行 过滤器
def host_news_class(index):
    if index == 1:
        return "first"
    elif index == 2:
        return "second"
    elif index == 3:
        return "third"
    else:
        return ""


# 获取用户登录信息装饰器
def user_login_data(f):
    @functools.wraps(f)
    def inner_func(*args, **kwargs):
        user_id = session.get("user_id")
        g.user = None
        if user_id:
            from info.models import User
            g.user = User.query.get(user_id)

        return f(*args, **kwargs)

    return inner_func
